<template>
	<view>
		<view class="cardWrap" @click="navgateTo(data)">
			<view class="left">
				<view class="img">
					<u-image width="100rpx" height="100rpx" :src="data.littleImgUrl"></u-image>
				</view>
			</view>
			<view class="right">
				<view class="top">
					<view class="title">
						{{data.name}}
					</view>
				</view>
				<view class="bottom">
					<view class="info">
						<view class="numinfo">
							浏览次数:{{data.browserCount}}
						</view>
						<view class="timeinfo">
							大小:{{data.sizeInfo}}
						</view>
					</view>
					<view class="delete">
						<u-button type="info" :custom-style="customStyle" @click="handleDelete()">{{deleteText}}</u-button>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle:{
					height:'45rpx'
				},
				deleteText:''
			};
		},
		beforeMount() {
			let routes = getCurrentPages();
			let curRoute = routes[routes.length - 1].route
			if(curRoute === 'pages/resource/myCollection/myCollection'){
				this.deleteText = '取消收藏'
			}else{
				this.deleteText = '删除'
			}
		},
		methods: {
			navgateTo(data) {
				this.$u.route('pages/resource/resourceDetail/resourceDetail', {
					id: data.id
				});
			},
			handleDelete(){
				console.log(this.data);
				if(this.deleteText === '取消收藏'){
					this.$api.favoriteDeleteBatch(this.$store.state.access_token,this.data.id)
					.then(res=>{
						console.log(res);
					})
				}else{
					this.$api.favoriteDeleteBatch(this.$store.state.access_token,this.data.id)
					.then(res=>{
						console.log(res);
					})
				}
			}
		},
		props: {
			data: {
				type: Object,
				default () {
					return {}
				}
			}
		},

	}
</script>

<style lang="scss">
	.cardWrap {
		display: flex;
		align-items: center;
		background-color: white;
		border-top: 1rpx solid $uni-bg-color;

		.left {
			box-sizing: border-box;
			padding: 10rpx 10rpx;

			.img {
				box-sizing: border-box;
				border: 1rpx solid white;
				border-radius: 10rpx;
			}
		}

		.right {
			.top {
				.title {
					font-size: 36rpx;
					display: -webkit-box;
					overflow: hidden;
					text-overflow: ellipsis;
					word-wrap: break-word;
					white-space: normal !important;
					-webkit-line-clamp: 1;
					-webkit-box-orient: vertical;
					margin-bottom: 20rpx;
				}
			}

			.bottom {
				display: flex;
				position: relative;
				width: 600rpx;
				.info {
					display: flex;
					color: gray;

					.numinfo {
						padding-right: 20rpx;
					}

					.timeinfo {}
					
				}
				.delete{
					position: absolute;
					right: 0;
				}
			}
		}
	}
</style>
